<?php
class OtherdocumentsController extends AppController {
	var $name = 'Otherdocuments';
	var $helpers = array('Html', 'Form');
	
	
	function index(){
		// для установки факультета и курса
		$this->loadModel('Facultet');
		$facultets = $this->Facultet->find('list');
		$this->set(compact('facultets'));
		$this->loadModel('Profession');
		$selectedprofessions = $this->Profession->find('list');
		$this->set(compact('selectedprofessions'));
		$this->loadModel('Course');
		$selectedcourses = $this->Course->find('list');
		$this->set(compact('selectedcourses'));
		$this->loadModel('Studentgroup');
		$selectedgroups = $this->Studentgroup->find('list');
		$this->set(compact('selectedgroups'));
		// вывод установки если есть
		// иницилизация переменных настроек
		$selectedfacultet = '';
		$selectedprofession = '';
		$selectedcourse = '';
		$selectedgroup = '';
		if ($this->Session->check('Settings')){
			$settings = $this->Session->read('Settings');
			$selectedfacultet = $settings['Settings']['selectedfacultet'];
			$selectedprofession = $settings['Settings']['selectedprofession'];
			$selectedcourse = $settings['Settings']['selectedcourse'];
			$selectedgroup = $settings['Settings']['selectedgroup'];
		}
		$this->set(compact('selectedfacultet', $selectedfacultet));
		$this->set(compact('selectedprofession', $selectedprofession));
		$this->set(compact('selectedcourse', $selectedcourse));
		$this->set(compact('selectedgroup', $selectedgroup));
		
		$this->loadModel('Student');
		$this->loadModel('Studentinfo');
		
		if ($selectedgroup){
		$students = $this->Student->find('all', array('conditions' => array('Student.studentgroup_id' => $selectedgroup)));
		$studentslist = array();
		foreach ($students as $student):
			$studentslist[$student['Student']['id']]= $student['Student']['lastname'].' '.$student['Student']['firstname'].' '.$student['Student']['surname'];
		endforeach;
		} else {
			$studentslist = '';
		}
		$this->set('students', $studentslist);
	}
	
	function studentdocument() {
		if (!empty($this->data)){
			$student_id = $this->data['Otherdocument']['student_id'];
			$this->loadModel('Student');
				$student = $this->Student->find('all', array('conditions' => array('Student.id' => $student_id)));
			
				$this->set('student', $student);
				
				$this->loadModel('Course');
				$courses = $this->Course->find('list');
				$this->set(compact('courses'));
				
				$this->loadModel('Facultet');
				$facultets = $this->Facultet->find('list');
				$this->set(compact('facultets'));
				

				
				if ($this->Session->check('Settings')){
					$settings = $this->Session->read('Settings');
					$selectedfacultet = $settings['Settings']['selectedfacultet'];
					$selectedprofession = $settings['Settings']['selectedprofession'];
				}
				$this->set(compact('selectedfacultet', $selectedfacultet));
				// выгружаем специальность и продолжительность обучения
				$this->loadModel('Profession');
				
				$professions = $this->Profession->find('all', array('conditions' => array('Profession.id' => $selectedprofession)));
				$this->set('professions', $professions);
				
			$this->render('/', 'blank', 'studentdocument');
		}
	}
}
?>